﻿// owner 蒋家伟
#pragma once
#include "Correspond_home.h"
#include "WeakReference.h"

namespace jsdk
{
    class ISerialPortEventHandler;
    class CORRESPOND_EXPORT ISerialPort :  public WeakReference
    {
    public:
        virtual ~ISerialPort() {};
        static OwnerPtr<ISerialPort> create(ISerialPortEventHandler * pSerialPortEventHandler = nullptr);

    public:
        /// \ 是否在线工作
        virtual bool isOnLine() const = 0;

        /// \ 链接
        /// \ note : 调用此接口后启动串口子线程，Create并不会启动
        /// \ in portName 串口名称
        /// \ in baudRate 波特率
        /// \ in dataBits 数据位数
        /// \ in stopBits 停止位
        /// \ in parity 校验位
        /// \ in flowControl 流控制
        virtual void connected(
            const std::string& portName,
            const int baudRate,
            const short dataBits,
            const short stopBits,
            const short parity,
            const short flowControl
            ) = 0;

        /// \ 重新链接
        /// \ in portName 串口名称
        /// \ in baudRate 波特率
        /// \ in dataBits 数据位数
        /// \ in stopBits 停止位
        /// \ in parity 校验位
        /// \ in flowControl 流控制
        /// \ note : 需要连接之后才可以调用
        virtual void reconnect(
            const std::string& portName,
            const int baudRate,
            const short dataBits,
            const short stopBits,
            const short parity,
            const short flowControl) const = 0;

        /// \ 发送消息
        /// \ in msg        发送的数据
        /// \ in length     发送的数据长度
        virtual void send(std::string&& msg, int64_t length) const = 0;
    };
}